﻿using System;
using System.Net;
using System.Runtime.Serialization;

namespace Toybox.NicoSharp.Video.MyPage
{
	using Abstracts;

	public class FriendList : MyPagePrimitives.AbstractMyPageList
	{

		#region Constructor

		public FriendList(CookieCollection cookies = null)
			: base(cookies)
		{
			this.Token = new Token(NicoUrls.VideoTop + "my/friend");
			this.Token.Type = TokenType.GlobalHash;
		}

		#endregion Constructor


		#region Public Methods

		public ListResult List()
		{
			string url = this.GetUrl("list");
			return this.Get<ListResult>(url);
		}

		public DelResult Delete(string target_user_id)
		{
			if (this.Token.Expired) this.Token.Update();

			string url = this.GetUrl("delete");
			string data = "target_user_id=" + target_user_id + "&token=" + this.Token.Value;
			return this.Post<DelResult>(url, data);
		}

		#endregion Public Methods

		#region Protected Methods

		protected override string GetUrl(string method)
		{
			return NicoUrls.FlApi + "friendlist/" + method;
		}

		#endregion Protected Methods


		#region [SubClass]

		[DataContract]
		public class ListResult : AbstractStatus
		{
			[DataMember]
			public Item[] friend;

			[DataMember]
			public int total_count;

			#region [SubClass]

			[DataContract]
			public class Item
			{
				[DataMember]
				public string id;

				[DataMember]
				public string nickname;

				[DataMember]
				public Uri thumbnail_url;

				[DataMember]
				public int create_time;

				[DataMember]
				public int last_login_time;
			}

			#endregion [SubClass]
		}

		[DataContract]
		public class DelResult : AbstractStatus
		{
		}

		#endregion [SubClass]

	}
}
